﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'P_InsertTreeBasicReferenceCodes')
	BEGIN
		DROP  Procedure  esf_sso.P_InsertTreeBasicReferenceCodes
	END

GO

CREATE Procedure esf_sso.P_InsertTreeBasicReferenceCodes
(
	@pParentCode	VARCHAR (100)
	,@pChildCode	VARCHAR (100)
	,@pID			INT	OUT
	,@pParentBasicReferenceTypeID INT 
	,@pChildBasicReferenceTypeID INT
	,@pValue VARCHAR (MAX) = NULL
)
AS

	DECLARE @parentID INT
	DECLARE @childID INT
		
	SET @parentID = (SELECT ID FROM esf_sso.BasicReference WHERE Code = @pParentCode AND BasicReferenceTypeID = @pParentBasicReferenceTypeID)
	SET @childID = (SELECT ID FROM esf_sso.BasicReference WHERE Code = @pChildCode AND BasicReferenceTypeID = @pChildBasicReferenceTypeID)

	EXEC esf_sso.P_InsertTreeBasicReferenceIDs @parentID, @childID, @pID OUT, @pValue

GO 